package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.article.entity.ApAuthor;
import com.heima.article.mapper.ApAuthorMapper;
import com.heima.article.service.IApAuthorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.common.dto.ResponseResult;
import org.springframework.stereotype.Service;

/**
 * <p>
 * APP文章作者信息表 服务实现类
 * </p>
 *
 * @author itheima
 * @since 2022-07-28
 */
@Service
public class ApAuthorServiceImpl extends ServiceImpl<ApAuthorMapper, ApAuthor> implements IApAuthorService {

    /**
     *  添加文章作者信息
     * @param apAuthor
     * @return
     */
    @Override
    public ResponseResult<ApAuthor> saveApAuthor(ApAuthor apAuthor) {

        //1.构建查询条件
        LambdaQueryWrapper<ApAuthor> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ApAuthor::getUserId,apAuthor.getUserId());

        ApAuthor one = this.getOne(queryWrapper);
        //判断条件
        if (one != null){
            //说明有该用户
            return ResponseResult.okResult(one);
        }
        //说明没有该用户 执行新增
        this.save(apAuthor);
        return ResponseResult.okResult(apAuthor);
    }
}
